package com.atguigu.mycloud.controller;

import com.atguigu.mycloud.Enum.ReturnMessage;
import com.atguigu.mycloud.entities.Pay;
import com.atguigu.mycloud.entity.PayDTO;
import com.atguigu.mycloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author 任浩
 * @version 1.0
 */

@RestController
@Tag(name = "支付微服务模块" ,description = "支付CRUD")
public class PayController {

    @Resource
    private PayService payService;

    @PostMapping("/pay/add")
    @Operation(summary = "添加" ,description = "新增支付流水方法,json串做参数")
    public ReturnMessage<Integer> add(@RequestBody Pay pay){
       int num = payService.add(pay);
       return ReturnMessage.success(num);
    }

    @DeleteMapping("/pay/delete/{id}")
    public ReturnMessage<Integer> delete(@PathVariable Integer id){
        int num = payService.deletePay(id);
        return ReturnMessage.success(num);
    }

    @GetMapping("/pay/get/{id}")
    public ReturnMessage<Pay> get(@PathVariable("id") Integer id){
        return ReturnMessage.success(payService.getPay(id));
    }

    @PutMapping("/pay/put")
    public ReturnMessage<Integer> update(@RequestBody PayDTO payDTO){
        Pay pay = new Pay();
        BeanUtils.copyProperties(payDTO,pay);
        int update = payService.update(pay);
        return ReturnMessage.success(update);
    }

    //进行测试从Consul得到配置信息。
    @GetMapping("/pay/consul")
    public String info(@Value("${info}") String info){
        return info;
    }
}
